(function(){
    "use strict";
    var dataShowController=function ($scope,$http,$modal,$location,toolsService,datashow_Service) {

        //加载页面时获得所有项目并赋值到select标签中
        $scope.prosInfoGet = function () {
            datashow_Service.findProject({"keyword": ""}).success(function (data) {
                if (data.result != null && data.result != undefined) {
                    $scope.projectList = data.result;
                    if ($scope.projectList != null && $scope.projectList.length > 0) {
                        //赋值项目ID
                        $scope.selectedProject = $scope.projectList[0];
                        $scope.projectId = $scope.selectedProject.id;
                        $scope.requirementsInfoGet();
                    }
                }
            });
        };
        $scope.prosInfoGet();

        // $scope.projectId = "5910215dc128f7141fdc7f38";
        //获取需求总数，以及显示最新的前10条未完成的需求信息
        $scope.requirementsInfoGet = function () {
            if ($scope.projectId == '0') {
                return;
            } else {
                datashow_Service.requirementsInfoGet({projectId: $scope.projectId}).success(function (data) {
                    if (true) {
                        $scope.requirementsInfo = data.result;
                    }
                });
            }
        };

        //修改项目的动作
        $scope.projectChange = function () {
            // $scope.clearTable(["compilecount","compilefailcount","staticcodeanalysis","utcovery","codesubmit","caseanalysis","buganalysis"]);
            if ($scope.selectedProject != undefined) {
                //赋值项目ID
                $scope.projectId = $scope.selectedProject.id;
                $scope.requirementsInfoGet();
            }
        };



    };

    angular.module("cicd.datashow",[])
        .controller("DataShowController",["$scope","$http","$modal","$location","toolsService","datashow_Service",dataShowController])
        .service("toolsService",[function () {
            "use strict";
            /**
             * 获取网址上的参数
             * @param name  网址上的参数.例如（id）
             * @param url   网址连接。
             * @returns {*}  返回网址参数的值
             */
            this.parameter = function (name, url) {
                var parameterString = null;
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                parameterString = url.substr(url.indexOf("?"), url.length);//获取截取？以后的字符串
                var r = parameterString.substr(1).match(reg);
                if (r != null){
                    return  unescape(r[2]);
                }
                return null;
            };
        }])

})();